﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Installer;

namespace DynCMS.NET.Infrastructure.IOC.Windsor
{
    public class Installer : IWindsorInstaller
    {
        public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
        {
            //var containerRegistration = new ComponentRegistration<Castle.Windsor.IWindsorContainer>();
            //containerRegistration.Instance(container);
            //container.Register(containerRegistration);

            //var spRegistration = new ComponentRegistration<Castle.Windsor.WindsorServiceProvider>();
            //spRegistration.ImplementedBy<Castle.Windsor.WindsorServiceProvider>();
            //container.Register(spRegistration);

            container.Register(
                Classes.FromThisAssembly()
                .IncludeNonPublicTypes()
                .Where(Component.IsInSameNamespaceAs<Installer>(true))
                .WithService.AllInterfaces()
                .LifestylePerThread());

            container.Register(
                Classes.FromAssemblyContaining<System.Web.Mvc.DefaultModelBinder>()
                .Where(type => !type.IsAbstract)
                .WithServiceAllInterfaces()
                .LifestylePerThread());

            //container.Install(Configuration.FromXmlFile("castle.xml"));
        }
    }
}